
Namespace WPF
    <ValueConversion(GetType(Integer), GetType(Visibility))> Public Class ItemsCountToVisibilityConverter
        Implements IValueConverter

#Region " Methods "

        ''' <summary>
        ''' Converter takes any integer as the value, if that integer is equal to or less than zero then converter returns either Collapsed or the value passed as the parameter, otherwise returns Visible.
        ''' </summary>
        ''' <param name="value">Integer</param>
        ''' <param name="targetType">UI Element</param>
        ''' <param name="parameter">Collapsed, Hidden or else nothing</param>
        ''' <returns>Visible, Hidden or Collapsed</returns>
        Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert

            If value Is Nothing OrElse CType(value, Integer) <= 0 Then

                If parameter Is Nothing Then
                    Return "Collapsed"

                Else

                    If TypeOf parameter Is String Then

                        Dim s As String = CType(parameter, String)

                        If s = "Collapsed" OrElse s = "Hidden" OrElse s = "Visible" Then
                            Return parameter
                        End If

                    End If

                    Return "Collapsed"
                End If

            Else
                Return "Visible"
            End If

        End Function

        Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
            Throw New NotSupportedException
        End Function

#End Region

    End Class

End Namespace
